package com.pwc.testing;

import java.io.File;
import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;
import org.springframework.stereotype.Component;

import com.pwc.common.Util.ILog;

@Component
public class Selenium {

	private WebDriver driver;

	private ISeleniumSystem seleniumSystem;

	private ISeleniumAction seleniumAction;

	private ISeleniumAssert seleniumAssert;

	private LogUtil log;

	public void initial(String driverPath, String type, LogUtil log) {

		if (BrowserType.CHROME.equalsIgnoreCase(type)) {
			ChromeOptions o = new ChromeOptions();
			o.addArguments("disable-extensions");
			o.addArguments("--start-maximized");
			System.setProperty("webdriver.chrome.driver", driverPath);
			driver = new ChromeDriver(o);
		} else if (BrowserType.FIREFOX.equalsIgnoreCase(type)) {
			File pathToBinary = new File(driverPath);
			FirefoxBinary ffBinary = new FirefoxBinary(pathToBinary);
			FirefoxProfile firefoxProfile = new FirefoxProfile();
			driver = new FirefoxDriver(ffBinary, firefoxProfile);
		}

		seleniumSystem = new SeleniumSystem(driver, log);
		seleniumAction = new SeleniumAction(driver, log);
		seleniumAssert=new SeleniumAssert(driver, log);
	}

	public ISeleniumSystem getSystem() {
		return seleniumSystem;
	}

	public void setSystem(ISeleniumSystem system) {
		this.seleniumSystem = system;
	}

	public ISeleniumAction getAction() {
		return seleniumAction;
	}

	public void close() {
		driver.close();
	}

	public ISeleniumAssert getAssert() {
		return seleniumAssert;
	}

	public void setAssert(ISeleniumAssert seleniumAssert) {
		this.seleniumAssert = seleniumAssert;
	}

	

}
